/*
 * @Description: 
 * @Author: zoe
 * @Date: 2024-10-08 09:26:16
 * @LastEditors: rendc
 * @LastEditTime: 2024-10-08 09:28:59
 */
import java.util.Comparator;
import java.util.TreeSet;

public class Test05_2_ReportCards {
    public static void main(String[] args) {
        // 定义 TreeSet 集合并传入一个自定义比较规则的 Comparator
        TreeSet<Student> set = new TreeSet<>(new Comparator<Student>() {
            @Override
            public int compare(Student s1, Student s2) {
                if (s1.getName().equals("tom")) {
                    return -1; // tom 总是在前面
                } else if (s2.getName().equals("tom")) {
                    return 1; // 其他学生在 tom 后面
                } else {
                    return Integer.compare(s2.getScore(), s1.getScore()); // 按分数降序排列
                }
            }
        });

        // 测试数据
        Student student1 = new Student("tom", 80);
        Student student2 = new Student("mike", 90);
        Student student3 = new Student("lily", 20);
        Student student4 = new Student("chris", 23);

        set.add(student3);
        set.add(student2);
        set.add(student1);
        set.add(student4);

        // 遍历并输出
        for (Student student : set) {
            System.out.println(student);
        }
    }
}

